/*
  两个日期时间之间相差 多少天多少小时多少分钟多少秒
  cosnt res = howLong(new Date(), new Date("2020-01-01 00:00:00"));
  console.log(res.day + "天 " + res.hours + "小时 " + res.minutes + "分钟 " + res.seconds + "秒");
*/
export const howLong = (time1, time2) => {
  time1 = time1.getTime()
  time2 = time2.getTime()
  var cha = time1 > time2 ? time1 - time2 : time2 - time1
  var day = Math.floor(cha / (24 * 3600 * 1000))
  var hours = Math.floor(cha % (24 * 3600 * 1000) / (3600 * 1000))
  var minutes = Math.floor(cha % (24 * 3600 * 1000) % (3600 * 1000) / (60 * 1000))
  var seconds = Math.floor(cha % (24 * 3600 * 1000) % (3600 * 1000) % (60 * 1000) / 1000)
  return {
    day: day,
    hours: hours,
    minutes: minutes,
    seconds: seconds
  }
}

// 把毫秒数转换天小时分钟秒的组合
export const getSecondMinuteFormat = (time1) => {
  var cha = time1
  var day = Math.floor(cha / (24 * 3600 * 1000))
  var hours = Math.floor(cha % (24 * 3600 * 1000) / (3600 * 1000))
  var minutes = Math.floor(cha % (24 * 3600 * 1000) % (3600 * 1000) / (60 * 1000))
  var seconds = Math.floor(cha % (24 * 3600 * 1000) % (3600 * 1000) % (60 * 1000) / 1000)
  return {
    day: day,
    hours: hours,
    minutes: minutes,
    seconds: seconds
  }
}
